package com.murphy.system.service.impl;

import com.murphy.system.dao.MenuMapper;
import com.murphy.system.model.Menu;
import com.murphy.system.service.MenuService;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by 31259 on 2017/12/20.
 */
@Service
public class MenuServiceImpl implements MenuService {

    @Autowired
    private MenuMapper menuMapper;

    @Override
    public int insert(Menu record) {
        return menuMapper.insert(record);
    }

    @Override
    public int insertSelective(Menu record) {
        return menuMapper.insertSelective(record);
    }

    @Override
    public List<Menu> getMenuList(Menu menu,boolean hasMenu) {
        List<Menu> list = menuMapper.getMenuListByType(Menu.MODULE);
        if(hasMenu){
            for (int i = 0; i < list.size(); i++) {
                list.get(i).setChildren(menuMapper.getChildList(list.get(i).getId()));
            }
        }
        return list;
    }



    @Override
    public List<Menu> getMenuListByType(String type) {
        return menuMapper.getMenuListByType(type);
    }

    @Override
    public List<Menu> getMenuList(Map<String, Object> map, int startRow, int countPerPage) {
        if(map == null){
            map = new HashMap<String, Object>();
        }
        map.put("startRow",startRow);
        map.put("count",countPerPage);
        return menuMapper.getMenuList(map);
    }

    @Override
    public int getMenuCount(Map<String, Object> map) {
        return menuMapper.getMenuCount(map);
    }

    @Override
    public String save(Menu menu) {
        menuMapper.insert(menu);
        return menu.getId();
    }


}
